package com.leetcode.math;

import java.util.Scanner;

public class IntegerToRoman {

	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		int num=in.nextInt();
		while(num!=-1){
			System.out.println(intToRoman(num));
			num=in.nextInt();
		}
		
	}
    public static String intToRoman(int num) {
        String roma[][]={
        		{"","I","II","III","IV","V","VI","VII","VIII","IX"},
        		{"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},
        		{"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"},
        		{"","M","MM","MMM"}
        };
        StringBuilder roman=new StringBuilder();
        roman.append(roma[3][num/1000%10]);
        roman.append(roma[2][num/100%10]);
        roman.append(roma[1][num/10%10]);
        roman.append(roma[0][num%10]);
        return roman.toString();
    }
}
